package io.jpress.addon.policiesregulations.service.provider;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import io.jboot.aop.annotation.Bean;
import io.jboot.db.model.Columns;
import io.jpress.addon.policiesregulations.service.JpressAddonPoliciesregulationsService;
import io.jpress.addon.policiesregulations.model.JpressAddonPoliciesregulations;
import io.jboot.service.JbootServiceBase;

@Bean
public class JpressAddonPoliciesregulationsServiceProvider extends JbootServiceBase<JpressAddonPoliciesregulations> implements JpressAddonPoliciesregulationsService {

    @Override
    public Page<JpressAddonPoliciesregulations> paginate(int page, int pageSize) {

        Page<JpressAddonPoliciesregulations> paginate = super.paginate(page, pageSize);
        if(paginate.getList()!=null && paginate.getList().size()>0) {
            for (JpressAddonPoliciesregulations j : paginate.getList()) {
                Record entity = Db.findById("addon_partnershipauthorities", j.getCountry());
                j.setCountryCh(entity.get("country_name_ch"));
                j.setCountryEh(entity.get("country_name_en"));
            }
        }
        return paginate;
    }

    @Override
    public Page<JpressAddonPoliciesregulations> paginateByColumns(int page, int pageSize, Columns columns) {
        Page<JpressAddonPoliciesregulations> jpressAddonPoliciesregulationsPage = super.paginateByColumns(page, pageSize, columns);
        if(jpressAddonPoliciesregulationsPage.getList()!=null && jpressAddonPoliciesregulationsPage.getList().size()>0) {
            for (JpressAddonPoliciesregulations j : jpressAddonPoliciesregulationsPage.getList()) {
                Record entity = Db.findById("addon_partnershipauthorities", j.getCountry());
                j.setCountryCh(entity.get("country_name_ch"));
                j.setCountryEh(entity.get("country_name_en"));
            }
        }
        return jpressAddonPoliciesregulationsPage;
    }

    @Override
    public Page<JpressAddonPoliciesregulations> paginateByColumns(int page, int pageSize, Columns columns,String order) {
        Page<JpressAddonPoliciesregulations> jpressAddonPoliciesregulationsPage = super.paginateByColumns(page, pageSize, columns,order);
        if(jpressAddonPoliciesregulationsPage.getList()!=null && jpressAddonPoliciesregulationsPage.getList().size()>0) {
            for (JpressAddonPoliciesregulations j : jpressAddonPoliciesregulationsPage.getList()) {
                Record entity = Db.findById("addon_partnershipauthorities", j.getCountry());
                j.setCountryCh(entity.get("country_name_ch"));
                j.setCountryEh(entity.get("country_name_en"));
            }
        }
        return jpressAddonPoliciesregulationsPage;
    }
}
